import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutterproject/util/extension/extension_util.dart';
import 'package:flutterproject/util/margin_padding_util.dart';
import 'package:flutterproject/widget/image_extended.dart';
import 'package:flutterproject/widget/text/text_field_common.dart';
import 'package:get/get.dart';

class InputEye extends StatefulWidget {
  final String hint;
  final TextEditingController? controller;
  final bool isShowEye;
  final bool isNumber;
  final bool isPhone;
  final ValueChanged<String>? onchange;
  final FocusNode? focusNode;

  const InputEye(
      {super.key,
      required this.hint,
      this.controller,
      this.isShowEye = false,
      this.isNumber = false,
      this.isPhone = false,
      this.onchange,
      this.focusNode});

  @override
  InputEyeState createState() => InputEyeState();
}

class InputEyeState extends State<InputEye> {
  late bool isEyeClose;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    isEyeClose = widget.isShowEye;
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        54.heightBox,
        TextFieldCommon(
          controller: widget.controller,
          height: 50.height,
          width: Get.width,
          hintText: widget.hint,
          size: 36.sp,
          hintSize: 28.sp,
          hintColor: Color(0xFFFF6F7277).withOpacity(0.5),
          textColor: Colors.black,
          inputFontWeight: FontWeight.bold,
          focusNode: widget.focusNode,
          suffixIcon: widget.isShowEye
              ? IconButton(
                  icon: ImageCommon(
                    isEyeClose ? "/icon/eye_close" : "/icon/eye_open",
                    width: 30.width,
                    height: 30.height,
                  ),
                  onPressed: onEyeClick)
              : null,
          obscureText: isEyeClose,
          keyboardType:
              widget.isNumber || widget.isPhone ? TextInputType.number : TextInputType.text,
          inputFormatters: !widget.isPhone
              ? []
              : [
                  LengthLimitingTextInputFormatter(11),
                  FilteringTextInputFormatter.digitsOnly,
                ],
          enabledBorderColor: Color(0xFFE4E9EB),
          focusedBorderColor: Color(0xFFE4E9EB),
          onChanged: (value) {
            widget.onchange?.call(value);
          },
        ),
        42.heightBox,
        Container(
          width: Get.width,
          height: 1,
          color: Color(0xFFE4E9EB),
        ),
      ],
    );
  }

  void onEyeClick() {
    isEyeClose = !isEyeClose;
    setState(() {});
  }
}
